package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Account  string `gorm:"type:varchar(50);not null"`
	Password string `gorm:"type:varchar(50);not null"`
}

func (u *User) Create() error {
	return DB.Create(&u).Error
}
func (u *User) Username() error {
	return DB.Where("account = ?", u.Account).Limit(1).Find(&u).Error
}

type New struct {
	gorm.Model
	Title   string `gorm:"type:varchar(50);not null"`
	Address string `gorm:"type:varchar(50);not null"`
	Img     string `gorm:"type:varchar(300);not null"`
	Order   int    `gorm:"type:int;not null"`
	Status  string `gorm:"type:varchar(50);not null"`
	People  string `gorm:"type:varchar(50);not null"`
}

func (n *New) Add() error {
	return DB.Create(&n).Error
}
func (n *New) Find() (new []*New, err error) {
	err = DB.Find(&new).Error
	return
}
func (n *New) Del() error {
	return DB.Delete(&n).Error
}
func (n *New) Hy() error {
	return DB.Where("id = ?", n.ID).Limit(1).Find(&n).Error
}

type Type struct {
	gorm.Model
	Status string `gorm:"type:varchar(50);not null"`
}

func (t *Type) Create() error {
	return DB.Create(&t).Error
}
